<?php
class Bap_sanggahan_model extends MY_Model {
	
    function Bap_sanggahan_model(){
        parent::MY_Model();
        $this->load->database();
        $this->table_name = "bap_sanggahan";
        $this->table_fields = array('bap_id', 'bap_sanggahan_pembuat_kary_id',
        	'bap_sanggahan_pembuat_kary_jbt_id', 'bap_sanggahan_tgl', 'bap_sanggahan_keterangan',
        	'bap_sanggahan_status',	'bap_sanggahan_status_kary_id',	'bap_sanggahan_status_kary_jbt_id',
        	'bap_sanggahan_status_keterangan', 'bap_sanggahan_status_change');
    }
    
    function select_by_id($id){
    	return $query = $this->db->get_where($this->table_name, array('bap_id' => $id));
    }
    
    function counterApprove($bap_id, $bap_sanggahan_status_kary_id,	
    	$bap_sanggahan_status_kary_jbt_id, $bap_sanggahan_status_keterangan, $bap_sanggahan_status_change){
    	return $this->_updateCounterRequest(
    		$bap_id,
    		"AP",	
    		$bap_sanggahan_status_kary_id,	
    		$bap_sanggahan_status_kary_jbt_id, 
    		$bap_sanggahan_status_keterangan, 
    		$bap_sanggahan_status_change); 
    }
    
    function counterReject($bap_id, $bap_sanggahan_status_kary_id,	
    	$bap_sanggahan_status_kary_jbt_id, $bap_sanggahan_status_keterangan, $bap_sanggahan_status_change){
    	return $this->_updateCounterRequest(
    		$bap_id,
    		"RE",
    		$bap_sanggahan_status_kary_id,	
    		$bap_sanggahan_status_kary_jbt_id, 
    		$bap_sanggahan_status_keterangan, 
    		$bap_sanggahan_status_change); 
    }
    
    function _updateCounterRequest($bap_id, $bap_sanggahan_status,	$bap_sanggahan_status_kary_id,	
    	$bap_sanggahan_status_kary_jbt_id, $bap_sanggahan_status_keterangan, $bap_sanggahan_status_change){
   	 	return $this->update(array('bap_id' => $bap_id),
    		array(
    		'bap_sanggahan_status'=>$bap_sanggahan_status,	
    		'bap_sanggahan_status_kary_id'=>$bap_sanggahan_status_kary_id,	
    		'bap_sanggahan_status_kary_jbt_id'=>$bap_sanggahan_status_kary_jbt_id, 
    		'bap_sanggahan_status_keterangan'=>$bap_sanggahan_status_keterangan, 
    		'bap_sanggahan_status_change'=>$bap_sanggahan_status_change)
    	); 
    }
}